//
//  LGAddPatientSelectView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/12/8.
//

#import "LGAddPatientSelectView.h"

@interface LGAddPatientSelectView()
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGAddPatientSelectView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.titleLabel];
        [self addSubview:self.contentTF];
        [self addSubview:self.tipView];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(viewPix(12));
            make.centerY.equalTo(self);
        }];
        [self.contentTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-viewPix(12));
            make.left.equalTo(self).offset(viewPix(110));
            make.top.bottom.equalTo(self);
        }];
        [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-viewPix(12));
            make.width.height.equalTo(@(viewPix(16)));
            make.centerY.equalTo(self);
        }];
    }
    return self;
}
-(void)setMaxNum:(NSInteger)maxNum{
    _maxNum = maxNum;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
}

-(void)setShowTip:(BOOL)showTip{
    _showTip = showTip;
    self.tipView.hidden = !showTip;
    self.contentTF.userInteractionEnabled = !showTip;
    CGFloat leftMargin = (showTip == YES)?viewPix(28):viewPix(12);
    [self.contentTF mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-leftMargin);
    }];
}

-(void)textFieldEditingChanged:(UITextField *)textField{
    if(self.maxNum>0){
        if(textField.text.length > self.maxNum){
            self.contentTF.text = [textField.text substringToIndex:self.maxNum];
        }
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UITextField *)contentTF{
    if(!_contentTF){
        _contentTF = [[UITextField alloc]init];
        _contentTF.tintColor = [UIColor colorWithString:@"#333333"];
        _contentTF.textColor = [UIColor colorWithString:@"#333333"];
        _contentTF.textAlignment = NSTextAlignmentRight;
        _contentTF.font = LGFont(15);
        [_contentTF addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    }
    return _contentTF;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
    }
    return _tipView;
}


@end
